﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Web.UI;
using NetDon.Utilities;

namespace NetDon.OA.Interface.Admin
{
  public  class PostData : DomainObject, IHierarchyData
    {
        public Guid PostId { get; set; }
        public string PostName { get; set; }
     
        public Guid PostLevel { get; set; }
       
      
        public string Comments { get; set; }
        public int? NodeLevel { get; set; }
        public Guid? ParentId { get; set; }



        #region Implementation of IHierarchyData
        
        public IHierarchicalEnumerable GetChildren()
        {
            var service = ServiceContainer.GetService<IPostService>();
            return new PostDataCollection(service.GetChildPosts(PostId));
        }

        public IHierarchyData GetParent()
        {
            if (ParentId.HasValue)
            {
                var service = ServiceContainer.GetService<IPostService>();
                return service.GetPost(ParentId.Value);
            }
            return null;
        }

        public bool HasChildren
        {
            get
            {
                var service = ServiceContainer.GetService<IPostService>();
                return service.GetChildPosts(PostId).Count > 0;
            }
        }

        public string Path
        {
            get;
            set;
        }

        public object Item
        {
            get { return this; }
        }

        public string Type
        {
            get { return typeof(CompanyData).FullName; }
        }

        #endregion
    }

    public class PostDataCollection : Collection<PostData>, IHierarchicalEnumerable
    {
        public PostDataCollection()
        {
        }

        public PostDataCollection(IEnumerable<PostData> categories)
        {
            foreach (var category in categories)
            {
                Add(category);
            }
        }
        #region Implementation of IHierarchicalEnumerable

        public IHierarchyData GetHierarchyData(object enumeratedItem)
        {
            return (PostData)enumeratedItem;
        }

        #endregion
    }
}
